<script type="text/javascript" src="{lib file=goodsinfo.js}" charset="utf-8"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak={$baidu_ak}"></script>
<script type="text/javascript">
    var market_ratio={$goods.market_price}/{$goods._specs.0.price};
//<!CDATA[
    /* buy */
    function buy()
    {
        if (goodsspec.getSpec() == null)
        {
            alert(lang.select_specs);
            return;
        }
        var spec_id = goodsspec.getSpec().id;

        var quantity = $("#quantity").val();
        if (quantity == '')
        {
            alert(lang.input_quantity);
            return;
        }
        if (parseInt(quantity) < 1)
        {
            alert(lang.invalid_quantity);
            return;
        }

        add_to_cart(spec_id, quantity);
    }

    /* add cart */
    function add_to_cart(spec_id, quantity)
    {
        var url = 'index.php?app=cart&act=add';

        $.getJSON(url, {'spec_id': spec_id, 'quantity': quantity}, function(data) {
            if (data.done)
            {
                $('.bold_num').text(data.retval.cart.kinds);
                $('.alert_text').text(lang.add_ok);
                $('.alert_text').css("left",get_width()+"px");
                $('.alert_text').show().delay(1000).fadeOut();
//                $('.bold_mly').html(price_format(data.retval.cart.amount));
//                $(".buynow .msg").slideDown().delay(5000).slideUp();
                // $('.msg').slideDown('slow');
                // setTimeout(slideUp_fn, 5000);
            }
            else
            {
//                alert(data.msg);
                $('.alert_text').text(data.msg);
                $('.alert_text').css("left",get_width()+"px");
                $('.alert_text').show().delay(1000).fadeOut();
            }
        });
    }

         /*buy_now*/
        function buy_now()
        {
            //验证数据
            if (goodsspec.getSpec() == null)
            {
                alert(lang.select_specs);
                return;
            }
            var spec_id = goodsspec.getSpec().id;

            var quantity = $("#quantity").val();
            if (quantity == '')
            {
                alert(lang.input_quantity);
                return;
            }
            if (parseInt(quantity) < 1)
            {
                alert(lang.invalid_quantity);
                return;
            }
            buy_now_add_cart(spec_id, quantity);
        }

        /* add buy_now_add_cart */
        function buy_now_add_cart(spec_id, quantity)
        {
            var url = SITE_URL + '/index.php?app=order&goods=single&store_id={$store.store_id}&share_id={$smarty.get.share_id}&spec_id='+spec_id+'&quantity='+quantity;
            location.href=url;return;
        }



var specs = new Array();
<!--{foreach from=$goods._specs item=spec}-->
<!--{if $spec.is_pro}-->
specs.push(new spec({$spec.spec_id}, '{$spec.spec_1|escape}', '{$spec.spec_2|escape}', '{$spec.spec_3|escape}', '{$spec.spec_4|escape}', {$spec.price},{$spec.pro_price}, {$spec.stock},true,{$spec.discount|default:0}));
<!--{else}-->
    console.log($goods)
specs.push(new spec({$spec.spec_id}, '{$spec.spec_1|escape}', '{$spec.spec_2|escape}', '{$spec.spec_3|escape}', '{$spec.spec_4|escape}', {$spec.price},0, {$spec.stock},false,{$spec.discount|default:0}));
<!--{/if}-->
<!--{/foreach}-->
var specQty = {$goods.spec_qty};
var defSpec = {$goods.default_spec|escape};
var goodsspec = new goodsspec(specs, specQty, defSpec);
//]]>


    function get_width(){
                B = $(".alert_text").width();
                cur = $(window).width()/2.0-(B/2.0)-5;
                return cur;
            }
    function decrease_quantity() {
        var item = $('#quantity');
        var orig = Number(item.val());
        if (orig > 1) {
            item.val(orig - 1);
            item.keyup();
        }
    }
    function add_quantity() {
        var item = $('#quantity');
        var orig = Number(item.val());
        item.val(orig + 1);
        item.keyup();
    }

                var shippings = {$shippings};
$(function(){
var my_region=$.getCookie('my_region');
if(!my_region){
var geolocation = new BMap.Geolocation();
            geolocation.getCurrentPosition(function(r) {
                if (this.getStatus() == BMAP_STATUS_SUCCESS) {
                    var lng = r.point.lng;
                    var lat = r.point.lat;
				
                $.post("index.php?app=goods&act=get_region_id",
                        {
                            lat: lat,
                            lng: lng,
                        },
                        function(result, status) {
                            
                        var result = eval ("(" + result + ")");
                        var cityName=result.retval.cityName;
		var region_id=result.retval.region_id;
	var layer=result.retval.layer;
        var region_name=result.retval.region_name;
        var son_flag=result.retval.son_flag;
	after_region(region_id,layer,region_name,son_flag,cityName);
        var exp = new Date();
        exp.setTime(exp.getTime() + 1000*86400*365);
        exp.toGMTString;
		my_region=new Array(region_id,layer,region_name,son_flag,cityName);
        $.setCookie('my_region',JSON.stringify(my_region),exp);
                        });

                }
                else {
                    alert('failed' + this.getStatus());
                }
            }, {enableHighAccuracy: true})


}else{
my_region=eval ("(" + my_region + ")");
var region_id=my_region[0];
var layer=my_region[1];
var region_name=my_region[2];

var son_flag=my_region[3];
var cityName=my_region[4];
after_region(region_id,layer,region_name,son_flag,cityName);
}
    
})
function after_region(region_id,layer,region_name,son_flag,cityName){
if(region_id && layer){
		var html='';
		var region_name=region_name;
		var i=0;
		for(var key in region_name){
			i++;
			var active='';
			if(!son_flag && i==layer){
				active='class="active"';
			}
			html+='<a href="javascript:void(0)" onclick="change_region('+i+','+key+',\''+region_name[key]+'\')" '+active+'>'+region_name[key]+'</a>';
		}

            if(son_flag){
            	html+='<a href="javascript:void(0)" class="active">请选择</a>';
            }
            
            html+='<div class="clear"></div>';
		$(".region_content .mt").html(html);
		change_region(layer,region_id,cityName);

	}
}
    function change_region(layer,region_id,region_name){

        layer && $(".region_content .mt a:eq("+(layer-1)+")").text(region_name);
        $("#region_names").text('');
        $(".region_content .mt a").each(function(){
            if(($(this).index()+1)>layer){
                $(this).remove();
            }else{
                $("#region_names").text($("#region_names").text()+$(this).text()+' ');
            }
        });
        
        var url = REAL_SITE_URL + '/index.php?app=mlselection&type=region';
        $.getJSON(url, {'pid': region_id}, function(data) {
            if (data.done)
            {
                if (data.retval.length > 0)
                {
                    if($(".region_content .mt a").length>0){
                        $(".region_content .mt a:last").after('<a href="javascript:void(0)" class="active">请选择</a>');
                    }else{
                        $(".region_content .mt").prepend('<a href="javascript:void(0)" class="active">请选择</a>');
                        $("#region_names").text('请选择');
                    }
                    $(".region_content .mc").html('');
                    var data = data.retval;
                    for (i = 0; i < data.length; i++)
                    {
                        $(".region_content .mc").append('<a href="javascript:void(0)" onclick="change_region('+(layer+1)+','+data[i].region_id+',\''+ data[i].region_name +'\')">'+ data[i].region_name +'</a>');
                    }
                    $(".region_content .mc").append('<div class="clear"></div>');
                }
                $(".region_content .mt a").removeClass('active');
                $(".region_content .mt a:last").addClass('active');
            }
            else
            {
                alert(data.msg);
            }
        });
        $("#region_id").val(region_id);
        get_shipping_fee();
    }
function get_shipping_fee(){
    for(shipping_id in shippings){
        
    
                    var shipping_data = shippings[shipping_id];
                    var first_price   = Number(shipping_data['first_price']);
                    var step_price   = Number(shipping_data['step_price']);
                    var _shipping_fee=0;
                    var cod_regions_price=shippings[shipping_id]['cod_regions_price'];
                    
                  //获取地区价格
                  var ajex_region_id;

                  ajex_region_id=$("#region_id").val();
                  
                  	var suitble_region=0;
                  for(var r_p in cod_regions_price){
                  	var region_price_array;
                    if(ajex_region_id==r_p){
                        
                        region_price_array=cod_regions_price[r_p].split(",");
                        step_price = parseFloat(region_price_array[2]);
                        if(isNaN(step_price)){
                            step_price=0;
                        }
                        if(!isNaN(parseFloat(region_price_array[1]))){
                        first_price=parseFloat(region_price_array[1]);
                        
                            break;
                        }

                       
                    }
                    
                   //获取地区的子孙
                   $.ajaxSettings.async = false; 
                      $.getJSON('index.php?app=mlselection&act=ajax_get_region_descendant&id='+r_p,function(result){
                  		if(result.done){
                  			var ids=result.retval;
                  			if($.inArray(ajex_region_id,ids)>-1){
                                  region_price_array=cod_regions_price[r_p].split(",");

                                  if((suitble_region==0) || (ids.length <suitble_region))
                                  {
                                      suitble_region=ids.length;
                        if(!isNaN(parseFloat(region_price_array[1]))){
                        first_price=parseFloat(region_price_array[1]);
                        
                        }
                                      
                                        step_price = parseFloat(region_price_array[2]);
                                        if(isNaN(step_price)){
                                            step_price=0;
                                        }
                                  }
                  			}
                  			
                  		}
                      });
                      
                  }

                
        var item = $('#quantity');
        var orig = Number(item.val());
        if(isNaN(orig)){
        orig=1;
        }
        if(orig<1){
        orig=1;
        }
                          var goods_shipping_fee=ForDight(first_price + (orig - 1) * step_price,2);
                          
                          
                          
                              $("#goods_shipping_"+shipping_id).text(price_format(goods_shipping_fee));
                          }                 
}
function   ForDight(Dight,How)  
{  
            Dight   =   Math.round   (Dight*Math.pow(10,How))/Math.pow(10,How);  
            return   Dight;  
}  
function showmoreship(obj){
    obj.css("height","auto");setTimeout(function(){obj.animate({height:'21px'});},3000);
}
</script>
<style>
.region_wrap{}
.region_wrap .region_content{display: none;position: absolute;top:35px;left: 10%;background: #fff;border:1px solid rgb(217, 27, 29);z-index: 10;padding:10px;width:80%;}


.region_wrap .region_content .mt{border-bottom: 1px solid rgb(217, 27, 29);height: 20px;margin-bottom: 10px;}
.region_wrap .region_content .mt a {display: block;float:left;padding:0 5px;height: 19px;line-height: 20px;margin-right: 5px;border:1px solid #eee;border-bottom: 0;margin-bottom: -1px;}
.region_wrap .region_content .mt a.active{border-color:rgb(217, 27, 29);border-bottom: 1px solid #fff }
.region_wrap .region_content .mc a{display: block;float:left;padding:0 10px;white-space: nowrap}
.shipping_wrap{position: absolute;height: 21px;overflow: hidden;z-index: 10;top:4px;left:4px;background-color: #fff;padding-right: 12px;}
.shipping_wrap .shipping_item{white-space: nowrap}
.detail_tit .goods_name{line-height: auto;height: auto;overflow: visible}
</style>
<div class="detail_img">
    <div id="slider" class="slider" >
        <ul id="sliderlist" class="sliderlist" >
            <!--{foreach from=$goods._images item=goods_image name=fe_goods_image}-->
            <li><img src="{$site_url}/{$goods_image.thumbnail}"></li>
            <!--{/foreach}-->
        </ul>
    </div>
    <script type="text/javascript">
        var t2 = new TouchSlider({id: 'sliderlist', speed: 600, timeout: 3000, before: function(index) {
            }});
    </script>
    <div class="fav">
        <a href="javascript:{if $if_collected}un{/if}collect_goods({$goods.goods_id});" class="iconfont collect_btn {if $if_collected}active{/if}">
            &#xf0114;
            <!--<span>收藏</span>-->
        </a>
    </div>
</div>

<div class="detail_tit">
    <p class='goods_name'>{$goods.goods_name|escape}</p>
    <p class="price"><strong ectype="goods_price">{$goods._specs.0.price|price}</strong>{if $goods.market_price>0}<span class="market_price" ectype="market_price">{$goods.market_price|price}</span>{/if} </p>
    <!--{if $goods.if_open}-->
	<p>
		<span class="integ">
        <!--{if $visitor.user_id }-->
        <em class="" title="{$goods.grade_name}">{$goods.grade_name}</em><span class="" ectype="member_price">{$goods._specs.0.member_price|price}</span>
        <!--{else}-->
        <em >{$lang.membership_price}</em>
        <!--{/if}-->
        </span>
	</p>
	<!--{/if}-->	
    <p class="other"><span class="sales fl">{$sales_info}</span>
    
    </p>
    <p class="other"><span class="fl">{$lang.region}：{if $goods.gregion_name|escape}{$goods.gregion_name|escape}{else}{$store.region_name|escape}{/if}</span></p>
                <div class="clearfix" style="position: relative;font-size: 14px">
      <p class="other" style="float:left;width: auto;"><span class="fl letter_width">{$lang.logistics}：</span></p>
      <div style="float:left">
          <div style="width:auto">
             <div id="region" class="clearfix about_shipping">
                 <div style="float:left;margin-top: 6px;" class="region_wrap">
                 <div class="region_names other"><span id="region_names" onclick="$('.region_content').toggle()">{$region_names|default:请选择}</span><b class="icon"></b>
                 <div class="region_content">
                         <div class="mt clearfix">
                           <!--{foreach from=$region_array item=name key=key name=fe_name}--> 
                           <a href="javascript:void(0)" onclick="change_region({$smarty.foreach.fe_name.iteration},{$key},'{$name}')" {if $region_len == $region_array.length && $smarty.foreach.last}class="active"{/if}>{$name}</a>
                           <!--{/foreach}-->
                           <!--{if $region_len > $smarty.foreach.fe_name.total}-->
                           <a href="javascript:void(0)" class="active">{$lang.pls_select}</a>
                           <!--{/if}-->
                           
                            <div class="clear"></div>
                     </div>
                     <div style="float:right;position: relative;top:-40px;"><a style="font-weight: bold;color:gray" href="javascript:void(0)" onclick="change_region(0,0,'{$lang.pls_select}');">更换省份</a></div>
                     <div class="mc clearfix">
                         <!--{foreach from=$regions item=region}-->  
                         <a href="javascript:void(0)" onclick="change_region({$region_len},{$region.id},'{$region.value}')">{$region.value}</a>
                         <!--{/foreach}-->
                         <div class="clear"></div>
                    </div>
                    </div>
                 </div>

                 </div>
                <div style="float:left ;position: relative">
                    
                    <div class="shipping_wrap" onclick='showmoreship($(this))'>
				
                      <!--{foreach from=$shipping_methods item=shipping_method name=shipping_select}-->
                <ul class="shipping_item" shipping_id="{$shipping_method.shipping_id}">
                    
                 <li{if $smarty.foreach.shipping_select.first && $smarty.foreach.shipping_select.total>1} class="relative"{/if}>
                     <div style="float:left">
                        {$shipping_method.shipping_name|escape}
                        <span ectype="shipping_fee" id="goods_shipping_{$shipping_method.shipping_id}">&yen; 0.00</span>
                     </div>
                     
                        <!--{if $smarty.foreach.shipping_select.first && $smarty.foreach.shipping_select.total>1}--><span class='iconfont' style="font-size:12px;-webkit-transform:scale(0.8,0.8);">&#xf0118;</span><!--{/if}-->
                        
                 <div class="clear"></div>    
                 </li>
                 </ul>
                      
                 <!--{/foreach}-->

                                 
                 </div>
                 
                 </div>
                 <div class="clear"></div>
                <input type="hidden" class="mls_id" name="region_id" id="region_id" value="{$last_region}"/>
             </div>
      </div>

                </div>
      <div style="clear:both;height:0; display:block; overflow:hidden"></div>
            </div>
</div>

<div class="detail_sales promo">
    <!--{if $store.enable_free_fee || $goods.integral_max_exchange}-->
    <div class="sales_box">
        <!--{if $store.enable_free_fee && $store.amount_for_free_fee neq '0.00'}--><span class="post"><img width="13" src="{res file=images/ico_ru.png}"/>{$lang.man}{$store.amount_for_free_fee|price}{$lang.yuan_shipping}</span><!--{/if}-->
        <!--{if $store.enable_free_fee && $store.acount_for_free_fee}--><span class="post"><img width="13" src="{res file=images/ico_ru.png}"/>{$lang.man}{$store.acount_for_free_fee|escape}{$lang.jian_shipping}</span><!--{/if}-->
        {if $goods.integral_max_exchange}<span class="post"><img width="13" src="{res file=images/ico_ru.png}"/>{$lang.use_integral}{$goods.integral_max_exchange|escape}</span>{/if}
    </div>
    <!--{/if}-->
    
   
    <div class="sales_box" ectype="is_pro" style="{if !$goods._specs.0.is_pro}display:none{/if}">
        <em class="promo-price-type" title="{$goods.pro_desc}">{$goods.pro_name}</em>
        <span class="promo-price" ectype="goods_pro_price">{$goods._specs.0.pro_price|price}</span>
        <a class="countdown J_Countdown_GoodsPromotion">
        <span class="lefttime">{$lang.the_remaining}</span>
        <span class="J_NumDays">{$goods.lefttime.d}</span><em>{$lang.day}</em>
        <span class="J_NumHours">{$goods.lefttime.h}</span><em>{$lang.hour}</em>
        <span class="J_NumMins">{$goods.lefttime.m}</span><em>{$lang.minute}</em>
        <span class="J_NumSeconds">{$goods.lefttime.s}</span><em>{$lang.seconds}</em>
        </a>
        <a class="fr iconfont arrow_r" href="{url app=promotion}">&#xf0116;</a>
    </div>
  
</div>
    
<div class="detail_size">
    <div class="size_con">
        <div class="handle">
            <!--{if $goods.spec_name_1}-->
            <ul id='handle_1'>
                <li class="handle_title">{$goods.spec_name_1|escape}: </li>
            </ul>
            <!--{/if}-->
            <!--{if $goods.spec_name_2}-->
            <ul id='handle_2'>
                <li class="handle_title">{$goods.spec_name_2|escape}: </li>
            </ul>
            <!--{/if}-->
            <!--{if $goods.spec_name_3}-->
            <ul id='handle_3'>
                <li class="handle_title">{$goods.spec_name_3|escape}: </li>
            </ul>
            <!--{/if}-->
            <!--{if $goods.spec_name_4}-->
            <ul id='handle_4'>
                <li class="handle_title">{$goods.spec_name_4|escape}: </li>
            </ul>
            <!--{/if}-->
            <ul class="quantity">
                <li class="handle_title">{$lang.quantity}: </li>
                <li>
                    <div class="quantity-wrapper">
                        <a class="quantity-decrease" href="javascript:decrease_quantity()"><em id="minus">-</em></a>
                        <input type="tel" class="text" size="4" value="1" id="quantity" >
                        <a class="quantity-increase" href="javascript:add_quantity()"><em id="plus">+</em></a>
                    </div>
                    {$lang.unit} {$lang.left_bracket}{$lang.stock}<span class="stock" ectype="goods_stock">{$goods._specs.0.stock}</span>{$lang.unit}{$lang.right_bracket}
                </li>
            </ul>
            <!--{if $goods.spec_qty gt 0}-->
            <ul class="selected">
                <li class="handle_title">{$lang.your_select}: </li>
                <li class="aggregate" ectype="current_spec"></li>
            </ul>
            <!--{/if}-->
        </div>
        <div class="buynow">
            <a href="javascript:buy_now();" class="buy">{$lang.purchase_now}</a><a href="javascript:buy();" class="add">{$lang.add_to_cart}</a>
            <div class="msg" style="display:none;">
                <p><b></b>{$lang.Shopping_common}<span class="bold_num"></span>{$lang.In_total} <span class="bold_mly" style="color:#8D0303;"></span>！</p>
                <a href="{url app=cart}" class="white_btn">{$lang.view_cart}</a>
                <a  onclick="$('.msg').css({'display': 'none'});" class="white_btn">{$lang.continue_shopping}</a>
            </div>
        </div>
    </div>
</div>
<dl class="list_entry clearfix">
    <dt class="store_logo">
        <img src="{$site_url}/{$store.store_logo}"/>
    </dt>				
    <dd>
        <a href="{url app=store&id=$store.store_id}" class="store_name">{$store.store_name|escape}</a>
         <!--{if $store.credit_value ge 0}--><span>{$lang.credit} <img src="{$store.credit_image}" alt="" /></span><!--{/if}-->
         <span><a href="http://wpa.qq.com/msgrd?v=3&uin={$store.im_qq}&site=qq&menu=yes" >{$lang.Contact_store}<i class="icon_dong"></i></a></span>
    </dd>
</dl>
    
    